package Function;

import Frame.FCProgressBar;
import Frame.FCTip;
import Frame.MapEditJpanel;
import VWorldGameStudio.FCMap;

public class FCCorrect extends Thread {
	private MapEditJpanel jpa;
	private FCBlockLibrary blol;
	private FCProgressBar bar;
	private int se = -1;

	public void setMapData(MapEditJpanel jpa, FCBlockLibrary blol, int se, FCProgressBar bar) {
		this.jpa = jpa;
		this.blol = blol;
		this.se = se;
		this.bar = bar;
	}

	public void correctMapData() {
		int num = 0, numm = 0;
		FCMap map = jpa.getNewMap();
		if (map != null) {
			num = map.getMapHeight() * map.getMapWidth() * 2;
			numm = 0;
			map = map.newMapEntity();
			for (int i = 0; i < map.getMapWidth(); i++)
				for (int j = 0; j < map.getMapHeight(); j++) {
					String mm = map.getUnplaceNameOfCoor(i, j);
					if (!mm.equals("v"))
						map = map.setMapEntityOfCoor(i, j, blol.getBlockOfID(mm));
//					try{Thread.sleep(50);}catch (Exception e) {}
					numm++;
					bar.setNum((double) numm / (double) num);
					mm = map.getPlaceNameOfCoor(i, j);
					if (!mm.equals("v"))
						map = map.setMapEntityOfCoor(i, j, blol.getBlockOfID(mm));
					numm++;
					bar.setNum((double) numm / (double) num);
				}
			if (numm < num) {
				new FCTip("地图检修", "检修失败!");
				bar.dispose();
			}
		} else
			new FCTip("地图检修", "未打开地图!");
	}

	@Override
	public void run() {
		switch (se) {
		case 0:
			correctMapData();
			break;
		}
	}
}
